<script type="text/javascript">
    var enable_submit = true;
    function submit_snapshot_clone() {
        var clone_volume_name = $("#volume_snapshot_clone").find("#clone_volume_name");
        var bValid = true;
        var pool_dropdown = $("#volume_snapshot_clone").find("#volume_pool_cr");
        bValid = bValid && checkRegexp(clone_volume_name, /^[0-9a-z-]+$/, "名称应由小写英文字母、数字或中划线(英文)构成。");
        bValid = bValid && checkLength(clone_volume_name, "名称", 1, 32);
        if (bValid) {
            if (enable_submit) {
                enable_submit = false;
                var $submitBtn = $('.modal-footer').find('.btn-blue');
                $submitBtn.html('<i class="fa fa-spinner fa-spin" style="margin:3px 6px;"></i>');
                $('.rtn-tip').slideUp('fast');
                $.post("/snapshot_clone", {
                        "tgt_volume": clone_volume_name.val(),
                        "pool_id": $.trim(pool_dropdown.attr('realvalue')),
                        "snapshotpath": "{{snapshotpath}}",
                        "id": "{{ snapshot.id }}"
                    },
                    function (data) {
                        if (data.reply.is_success) {
                            angular.element('#snapshot_create').scope().close();
                            $('#snapshot_table').trigger("reloadGrid");
                            //snapshots_show("{{ snapshot.volume_id }}");
                            //SelfAlert("克隆存储卷完成", "完成提示");
                        } else {
                            error = data.reply.error;
                            $('.rtn-tip').text(error).slideDown('fast');
                            $submitBtn.html(SelfTranslate("[[ 'label ok'|translate ]]"));
                            enable_submit = true;
                        }
                    });
            }
        }
    }

    $(function () {
        var volume_pool = new Array();
        {% for pool in pools %}
        var values = new Array();
        values[0] = "{{pool.id}}";
        values[1] = "{{pool.path}}";
        volume_pool.push(values);
        {% endfor %}
        $('#volume_snapshot_clone #volume_pool_cr').rqDropDown({
            position:true,
            "datatype":"local",
            "source":volume_pool ,
        });

        var obj = {
            "clone_volumn_name": "由1至32位小写英文字母、数字、中划线构成。"
        }
        bindMouseEvent('#volume_snapshot_clone', obj);
    });
</script>
<div class="modal-header">
    <h3>克隆存储卷</h3>
</div>
<div class="modal-body modal-body-height" id="volume_snapshot_clone">

    <div class="snapshot-clone-box">
        <div class="rtn-tip"></div>
        <table class="base-info">
            <tr>
                <td>
                    <label>名称</label><a>*</a>
                </td>
                <td colspan="3">
                    <input id="clone_volume_name" name="clone_volume_name" size="25" type="text"/>
                    <i class="fa fa-question-circle" itype="clone_volumn_name"></i>
                </td>
            </tr>
            <tr>
                <td>
                    <label>存储池</label><a>*</a>
                </td>
                <td>
                    <input id="volume_pool_cr" readonly="readonly" class="rounded_dropdown" value='{{pool.path}}'
                           realvalue="{{pool.id}}"/>
                </td>
                <td></td>
                <td></td>
            </tr>
        </table>
    </div>
    <div class="error-tip">
        <p></p>
        <span></span></div>
    <div class="tip">
        <p></p>
        <span></span></div>
</div>
<div class="modal-footer">
    <button class="btn btn-blue" ng-click="clone_ok()">[[ 'label ok'|translate ]]</button>
    <button class="btn btn-white" ng-click="cancel()">[[ 'label cancel'|translate ]]</button>
</div>
